<%@ page import="java.util.HashMap,
                java.util.ArrayList,
                java.util.Iterator,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.User"%>
<%@ page import="com.scalar.chiptrack.operations.discrepancyLotsNotifications.DiscrepancyLot"%>
<%@ page import="com.scalar.chiptrack.operations.discrepancyLotsNotifications.dao.DiscrepancyLotsNotificationsDAO"%>
<%@ page import="com.scalar.chiptrack.commons.Constants"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/jsp/operations/show_discrepancy_lots.jsp"/>

<html:html>

<HEAD><TITLE>Scalar Soft - ChipTrac</TITLE>

<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<script language='javascript'>
    function viewDetails(alarmId, alarmType)
    {
        //@todo add url
        var tempURL = ''
        newWindow = window.open (tempURL,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=800,height=400,resizable=yes');
        newWindow.focus();
    }

    function setSelectAll(object){

        var selectAllName = object.name;
        var tempname=selectAllName.substring(0,selectAllName.length-1);

        var tempobj1 = eval("document.discrepancyLots."+tempname+"1");
        var tempobj2 = eval("document.discrepancyLots."+tempname+"2");


        var result = object.checked+"";

        result = (result == 'true' )? true : "";
        tempobj1.checked=result;
        tempobj2.checked=result;

        var cGroup = eval('document.discrepancyLots.'+object.value);

        setAllCheckBoxes(result,cGroup);

    }

    function setAllCheckBoxes(status, cGroup){
        if ( typeof cGroup == 'object' ){

            if ( typeof cGroup.length == 'undefined'){
                cGroup.checked = status;
            }
            else {
                for (var idx = 0; idx < cGroup.length;idx++){
                    cGroup[idx].checked = status;
                }
            }
        }
    }

    function deSelectAll(object)
    {
        var aCheckBoxes = document.getElementsByName(object.name);
        var selectedName = object.name;
        var tempobj1 = eval("document.discrepancyLots."+selectedName+"_1");
        var tempobj2 = eval("document.discrepancyLots."+selectedName+"_2");

        if (aCheckBoxes.length == null) {
            if (aCheckBoxes.checked == true){
                    tempobj1.checked = true;
                    tempobj2.checked = true;
            }
            else {
                    tempobj1.checked = false;
                    tempobj2.checked = false;
           }
        }
        else {
            var status = true ;
            for (var index = 0 ; index < aCheckBoxes.length ; index++) {
                if ( aCheckBoxes[index].checked == false) {
                    status = false;
                    tempobj1.checked = false;
                    tempobj2.checked = false;
                    break;
                }
            }

            if (status == true ){
                    tempobj1.checked = true;
                    tempobj2.checked = true;
            }
        }

    }

    function ShowHide( menuID)
    {
        var menuObj = document.getElementById("Link"+menuID);
        var cellbk = document.getElementById("Head"+menuID);
        var messagesHolder = document.getElementById("infoMessages");
        messagesHolder.innerHTML = "";
        messagesHolder = document.getElementById("errorMessages");
        messagesHolder.innerHTML = "";

        if ( menuObj.className == "LINKSON")
        {
            menuObj.className="LINKSOFF"
            cellbk.style.backgroundColor="#FFFFFF"
            statusMessage = 'Click here to Expand';
        }
        else
        {
            menuObj.className="LINKSON"
            cellbk.style.backgroundColor="#FFFFFF"
            statusMessage = 'Click here to Collapse';
        }
    }

    function removeDiscrepancyLots( notificationType )
    {
        document.discrepancyLots.action = document.discrepancyLots.action + '?action=delete&notificationType='+notificationType;
        document.discrepancyLots.submit();
    }
    function closedlotnotifications()
    {
       var tempURL = '<%=chipTracContext%>/jsp/operations/show_closed_discrepancy_lots.jsp'
       newWindow = window.open (tempURL,'optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=800,height=400,resizable=yes');
    }
</script>

<style>
    <!--
    a.nav:link   { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none }
    a.nav:visited { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none }
    a.nav:active { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none }
    a.nav:hover  { font-family: Verdana,Arial,San Serif; font-size: 10px; text-decoration: none; color: #000000 }
    .HEADING     { cursor: hand; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #000000;
                   background-color: #FFFFFFF; font-weight: none;border: 1 solid #000000 }
    .LINKSOFF    { display: none; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #000000; }
    .LINKSON     { display: inline; font-family: Verdana,Arial,San Serif; font-size: 12px; color: #000000; }
    -->
</style>
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">
<TABLE  id="datatable"  cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TR>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
        <TD bgcolor="#ffffff"><IMG height=100 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
        <TD valign="top" width="80%">
            <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
            <BR>
            <html:form name='discrepancyLots' type='com.scalar.chiptrack.ChipTrackActionForm' action='/discrepancyLotsNotifications'>
                <table align="left" border="0" width="85%">
                <tr>
                    <td>
                        <center><span class="NArialW"><img src='<%=chipTracContext%>/jsp/includes/images/alarm_icon.jpg' height='46' width='34'>&nbsp;Discrepancy Lot Notifications </span></center>
                    </td>
                </tr>
                <a name="#top"/>
                <tr><td><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=30></td></tr>
                <tr><td  id="infoMessages"><chiptrack:info styleClass='NArialL'/></td></tr>
                <tr><td  id="errorMessages"><chiptrack:errors styleClass='NArialL'/></td></tr>
                <tr>
                    <td colspan=8 class="NArialL" align='center'>
                        Please&nbsp;<a href="javascript:closedlotnotifications();" onMouseOver="window.status='Click here to view closed lot notifications';return true" onmouseout="window.status='';return true">click here</a>&nbsp;to view the Closed Discrepancy Lot Notifications
                    </td>
                </tr>
                <tr><td colspan=8 align="left" class='NArialL'>&nbsp;</td></tr>
                <%
                    HashMap discrepancyLotsMap = null;
                    try
                    {
                        discrepancyLotsMap = DiscrepancyLotsNotificationsDAO.loadDiscrepancyLotsByStatus(Constants.STATUS_OPEN );
                    }
                    catch(Exception e)
                    {

                    }
                    if ((discrepancyLotsMap == null) || (discrepancyLotsMap.isEmpty()))
                    {
                %>
                <tr><td align='center'><font class='NArialL'><font color='green'>No Notifications</font></font></td></tr>
                <%
                    }
                    else
                    {
                        Iterator keys = discrepancyLotsMap.keySet().iterator();
                        String key = null;
                        ArrayList lotsList = null;
                        DiscrepancyLot discrepancyLot = null;

                        int index = 0;
                        String headValue = null;
                        String linkValue = null;
                        String showHide = null;
                %>
                <tr><td align='center'><font class='NArialS'><font color='blue'>[Click on bars to Expand or Collapse the List]</font></font></td></tr>
                <%
                        while (keys.hasNext())
                        {
                            key = (String) keys.next();
                            lotsList = (ArrayList) discrepancyLotsMap.get (key);
                            headValue = "head" + index;
                            linkValue = "link" + index;
                            showHide = "ShowHide(" + index + ")";
                %>
                <tr><td ID='<%=headValue%>' ALIGN='left' CLASS="HEADING" ONCLICK='<%=showHide%>'  onMouseOver="window.status='Click here to Expand/Collapse';return true" onmouseout="window.status='';return true"><%=key%> Notifications</td></tr>
                <tr><td ALIGN="left" bgcolor="#FFFFFF">
                <div ID='<%=linkValue%>' CLASS="LINKSOFF">
                    <table border="0" width="100%"  align=left>
                        <tr><td><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=5></td></tr>
                        <tr bgcolor="#993333">
                            <td width='20%' align='center'><font class='NArialL'><font color='#FFFFFF'>Select to Remove</font></font>
                            </td>
                            <td><font class='NArialL'><font color='#FFFFFF'>Lot Number</font></font></td>
                            <%
                                if( Constants.MISSMATCH_OF_TESTED_QTY_AND_GDPW.equalsIgnoreCase(key) ||  Constants.MRB_LOTS_DISPOSITION.equalsIgnoreCase(key))
                                {
                            %>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Wafer Id</font></font></td>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Vendor</font></font></td>
                            <%
                                }
                                else if( Constants.YIELD_DROPPED_BY_80_PERCENT.equalsIgnoreCase(key) || Constants.YIELD_GREATER_THAN_100_PERCENT.equalsIgnoreCase(key))
                                {
                            %>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Previous Process</font></font></td>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Current Process</font></font></td>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Previous Quantity</font></font></td>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Current Quantity</font></font></td>
                            <%
                                }
                                else if( Constants.MISSMATCH_OF_SHIPPED_QTY_AND_RECEIVED_QTY.equalsIgnoreCase(key))
                                {
                            %>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Wip Quantity</font></font></td>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Ship Quantity</font></font></td>
                                    <td><font class='NArialL'><font color='#FFFFFF'>Current Process</font></font></td>
                           <%
                               }
                           %>
                           <td><font class='NArialL'><font color='#FFFFFF'>Notification Date</font></font></td>
                        </tr>
                        <tr bgcolor="#FFFFEE">
                            <td width='20%' align='center'> <font class='NArialL'><input  type="checkbox" name='<%="notificationType"+index+"_1"%>'  value='<%="notificationType"+index%>' onClick = "javascript:setSelectAll(this)" >Select All</font></td>
                            <%
                                if( Constants.MISSMATCH_OF_TESTED_QTY_AND_GDPW.equalsIgnoreCase(key) ||  Constants.MRB_LOTS_DISPOSITION.equalsIgnoreCase(key))
                                {
                            %>
                                    <td colspan='3'><font class='NArialL'><font color='#FFFFFF'>&nbsp;&nbsp;</font></font></td>
                            <%
                                }
                                else if( Constants.YIELD_DROPPED_BY_80_PERCENT.equalsIgnoreCase(key) || Constants.YIELD_GREATER_THAN_100_PERCENT.equalsIgnoreCase(key))
                                {
                            %>
                                    <td colspan='5'><font class='NArialL'><font color='#FFFFFF'>&nbsp;&nbsp;</font></font></td>
                            <%
                                }
                                else if( Constants.MISSMATCH_OF_SHIPPED_QTY_AND_RECEIVED_QTY.equalsIgnoreCase(key))
                                {
                            %>
                                    <td colspan='4'><font class='NArialL'><font color='#FFFFFF'>&nbsp;&nbsp;</font></font></td>
                            <%
                                }
                            %>
                                <td><font class='NArialL'><font color='#FFFFFF'>&nbsp;&nbsp;</font></font></td>
                            </tr>
                        <%
                                if ((lotsList != null) && (!lotsList.isEmpty()))
                                {
                                    int size = lotsList.size();
                                    String bgColor[] = {"#DEE1E2", "#FFFFEE"};
                                    for (int i=0; i<size; i++)
                                    {
                                        discrepancyLot = (DiscrepancyLot) lotsList.get (i);
                        %>
                        <tr bgcolor='<%=bgColor[i%2]%>'>
                            <td width='20%' align='center'><font class='NArialL'><input  type='checkbox' name='<%="notificationType"+index%>' value='<%=discrepancyLot.getNotificationId()%>' onClick ="javascript:deSelectAll(this)"></font></td>
                            <td>
                                <font class='NArialL'><%=discrepancyLot.getLotNumber()%></font>
                            </td>
                            <%
                                if( Constants.MISSMATCH_OF_TESTED_QTY_AND_GDPW.equalsIgnoreCase(key) ||  Constants.MRB_LOTS_DISPOSITION.equalsIgnoreCase(key))
                                {
                            %>
                                    <td><font class='NArialL'><%=discrepancyLot.getWaferId()%></font></td>
                                    <td><font class='NArialL'><%=discrepancyLot.getVendor()%></font></td>
                            <%
                                }
                                else if( Constants.YIELD_DROPPED_BY_80_PERCENT.equalsIgnoreCase(key) || Constants.YIELD_GREATER_THAN_100_PERCENT.equalsIgnoreCase(key))
                                {
                            %>
                                    <td><font class='NArialL'><%=discrepancyLot.getPrevProcess()%></font></td>
                                    <td><font class='NArialL'><%=discrepancyLot.getCurrentProcess()%></font></td>
                                    <td><font class='NArialL'><%=discrepancyLot.getPrevQty()%></font></td>
                                    <td><font class='NArialL'><%=discrepancyLot.getCurrentQty()%></font></td>
                            <%
                                }
                                else if( Constants.MISSMATCH_OF_SHIPPED_QTY_AND_RECEIVED_QTY.equalsIgnoreCase(key))
                                {
                            %>
                                    <td><font class='NArialL'><%=discrepancyLot.getCurrentQty()%></font></td>
                                    <td><font class='NArialL'><%=discrepancyLot.getShipQty()%></font></td>
                                    <td><font class='NArialL'><%=discrepancyLot.getCurrentProcess()%></font></td>
                            <%
                                }
                            %>
                                <td>
                                    <font class='NArialL'><%=discrepancyLot.getNotificationDate() %></font>
                                </td>
                        </tr>
                        <%
                                    }
                        %>
                        <tr bgcolor="#FFFFEE">
                            <td width='20%' align='center'> <font class='NArialL'><input  type="checkbox" name='<%="notificationType"+index+"_2"%>'  value='<%="notificationType"+index%>' onClick = "javascript:setSelectAll(this)" >Select All</font></td>
                            <%
                                if( Constants.MISSMATCH_OF_TESTED_QTY_AND_GDPW.equalsIgnoreCase(key) ||  Constants.MRB_LOTS_DISPOSITION.equalsIgnoreCase(key))
                                {
                            %>
                                    <td colspan='3'><font class='NArialL'><font color='#FFFFFF'>&nbsp;&nbsp;</font></font></td>
                            <%
                                }
                                else if( Constants.YIELD_DROPPED_BY_80_PERCENT.equalsIgnoreCase(key) || Constants.YIELD_GREATER_THAN_100_PERCENT.equalsIgnoreCase(key))
                                {
                            %>
                                    <td colspan='5'><font class='NArialL'><font color='#FFFFFF'>&nbsp;&nbsp;</font></font></td>
                            <%
                                }
                                else if( Constants.MISSMATCH_OF_SHIPPED_QTY_AND_RECEIVED_QTY.equalsIgnoreCase(key))
                                {
                            %>
                                    <td colspan='4'><font class='NArialL'><font color='#FFFFFF'>&nbsp;&nbsp;</font></font></td>
                            <%
                                }
                            %>
                                <td><font class='NArialL'><font color='#FFFFFF'>&nbsp;&nbsp;</font></font></td>
                        </tr>
                        <tr><td colspan='2'><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
                        <tr>
                            <%
                                if( Constants.MISSMATCH_OF_TESTED_QTY_AND_GDPW.equalsIgnoreCase(key) ||  Constants.MRB_LOTS_DISPOSITION.equalsIgnoreCase(key))
                                {
                            %>
                                    <td align='center' class='NArialL' colspan='5'>
                            <%
                                }
                                else if( Constants.YIELD_DROPPED_BY_80_PERCENT.equalsIgnoreCase(key) || Constants.YIELD_GREATER_THAN_100_PERCENT.equalsIgnoreCase(key))
                                {
                            %>
                                    <td align='center' class='NArialL' colspan='7'>
                            <%
                                }
                                else if( Constants.MISSMATCH_OF_SHIPPED_QTY_AND_RECEIVED_QTY.equalsIgnoreCase(key))
                                {
                            %>
                                    <td align='center' class='NArialL' colspan='6'>
                            <%
                                }
                                String removeJSFunction = "javascript:removeDiscrepancyLots('notificationType"+index+"');";
                            %>
                                <chiptrack:restrictedLink functionality='<%=Functionality.DISCREPENCY_LOT_NOTIFICATIONS %>' action='<%=User.USER_ACTION_DELETE%>' href='<%=removeJSFunction%>' onmouseover="window.status='Click here to delete the Discrepancy Lots';return true" onmouseout="window.status='';return true">Delete</chiptrack:restrictedLink>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a href="#"  onMouseOver="window.status='';return true">Top</a>
                            </td>
                        </tr>
                        <%
                                }
                                else
                                {
                        %>
                        <tr><td colspan='2' align='center'><font class='NArialL'>No Alarms found under this category</font></td></tr>
                        <%
                                } // end of the else block of arraylist
                        %>
                    </table>
                </div>
                </td></tr>
                <tr><td><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=1></td></tr>
                <%
                            index ++;
                        }  // end of the while block of Hashmap iterator
                    } // end of else block of if(alarmMap == null) || (alarmMap.isEmpty() == true)
                %>

                </table>
        </html:form>
        <BR><BR><BR>
        </TD>
        <TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
    </TR>
</TABLE>
</BODY>
</html:html>